git clone --bare https://gitee.com/victorxuyuwei/dotfiles $HOME/.dotfiles

config() {
	/usr/bin/git --git-dir=$HOME/.dotfiles/ --work-tree=$HOME "$@"
}

mkdir -p $HOME/.config-backup
config checkout

if [ $? = 0 ]; then
  echo "Checked out config.";
  else
    echo "Backing up pre-existing dot files.";
    config checkout 2>&1 | egrep "\s+\." | awk {'print $1'} | xargs -I{} mv $HOME/{} $HOME/.config-backup/{}
fi;


if ! grep -q '.scripts/up.sh' $HOME/.bashrc; then
  init_cmd='export USE_PROXY=1\n[ -f "$HOME/.scripts/up.sh" ] && \. "$HOME/.scripts/up.sh"'
  # echo '[ -f "$HOME/.scripts/up.sh" ] && \. "$HOME/.scripts/up.sh"' >> $HOME/.bashrc
  echo $init_cmd >> $HOME/.bashrc
  [ -f "$HOME/.zshrc" ] && echo $init_cmd >> $HOME/.zshrc
fi

config checkout
config config status.showUntrackedFiles no
